//lightbox script javascripts-popup.js
function popupShow(id){document.getElementById(id).style.display='block';}
function popupHide(id){document.getElementById(id).style.display='none';}

$(window).load( function(){
 
  initializeRotator();
  loadMarketingTagsAndSocialWidgets();
  loadHomepageServiceSeals();
	
});

/* 
 * Slideshow Controls...
 * In order to make the homepage load as quickly as possible. We only want to 
 * load the first image in the rotator when the page loads.  We'll load the 
 * rest of the images after the 'ready' event is fired. Then, once all those 
 * images have finished loading, we'll start the rotator.
 */				
function initializeRotator() {
  /*
   * Count how many rotator slide images that we have to load. We will want to 
   * make sure all of them are loaded before we start to rotate the images.
   */
  var rotatorSlidesToLoad = $('.rotator img:not(.first)').length;
	
  /*
   * Start loading each rotator image by taking the value of the data-url 
   * attribute and setting the it to the src attribute.  This automatically 
   * starts the loading process.  The load events on these image tags will tell 
   * us when loading is complete.
   */
  $('.rotator img:not(.first)').each( function( index ) {
    $(this).attr('src', $(this).attr('data-url') );
  });

  /*
   * Listen for the load event on each of the rotator images that we are 
   * lazy-loading. (This is all of the images in the rotator, except the first 
   * one.)
   */
  $('.rotator img:not(.first)').load( function() {

    /*
     * We can't be exactly sure of the order in which loading will complete, 
     * since some images may be big and others may be small.  So, we'll just 
     * decrement the number of 'rotatorSlidesToLoad' each time one finishes 
     * loading.
     */
    rotatorSlidesToLoad--;

    /*
     * Then, when ther are no more left to load...
     */
    if ( rotatorSlidesToLoad == 0 ) {

      /*
       * We'll attach our double-synchronized rotator and start it!
       */
      $('.rotator').each(function(index) {
        $(this).cycle({
        fx:     'fade',
        timeout: 7000,
        speed:   600,
        cleartype: 1,
        delay: -1000,
        pager:  '.slide-nav',
		after: onAfter,
        pagerAnchorBuilder: function(idx, slide) {  
            return '.slide-nav li.slide-number:eq(' + idx + ') a'; 
          }        
        });
		// make the CTA trackable
    	function onAfter(curr, next, opts){
			var identifier = $('.rotator-ct .activeSlide a').attr('data-cta-link');			
			$('.trackable-rotator .main-button a').attr('href',identifier);
		};
      });
    
    }

  });

	/*pause on click*/
	$('.slide-nav li.slide-number a').click(function() { 
	    $('.rotator').cycle('pause'); 
	});
			
}

function loadMarketingTagsAndSocialWidgets() {
  Modernizr.load( [
    'https://tags.mediaforge.com/js/499'
  ] );
}

function loadHomepageServiceSeals() {
  $('.homepage_service_seal').each( function() {
    $(this).attr( 'src', $(this).attr( 'data-url' ) );
  });
}
